﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace ArasPLMExtend
{
    public partial class FrmTZSelected : Form
    {
        public FrmTZSelected()
        {
            InitializeComponent();
        }
        int idFlag;
        /// <summary>
        /// 通用窗体
        /// </summary>
        /// <param name="flag">int 1为工艺批量上传，2为检验指导书批量上传</param>
        public FrmTZSelected(int flag)
        {
            InitializeComponent();
            idFlag = flag;
        }
        private void FrmTZSelected_Load(object sender, EventArgs e)
        {

        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            CPublicState.checkFolderPath = "";
            CPublicState.tzFolderPath = "";
            switch(idFlag)
            {
                case 1:
                    CPublicState.tzFolderPath = tbxFolderPath.Text;
                    break;
                case 2:
                    CPublicState.checkFolderPath = tbxFolderPath.Text;
                    break;
            }
            if (!ERPConnection.CERPFunction.checkPrdNo(tbxPrdNo.Text.ToUpper().Trim()))
            {
                MessageBox.Show("输入的货品在ERP中不存在，请核查！");
            }
            else
            {
                CPublicState.updatePrdNo = tbxPrdNo.Text.ToUpper().Trim();
                CPublicState.prdinfo = ERPConnection.CERPFunction.getPrdInfoByPrdNo(CPublicState.updatePrdNo);
                CPublicState.tzlist =ERPConnection.CERPFunction.checkTZWhereCompByPrdNo(CPublicState.updatePrdNo);
                if (CPublicState.tzlist != null && CPublicState.tzlist.Count > 0)
                {
                    this.DialogResult = DialogResult.OK;
                    this.Close();
                }
                else
                {
                    this.DialogResult = DialogResult.Cancel;
                    MessageBox.Show("ERP中不存在相关制程，请检查ERP!");
                    this.Close();
                }
            }
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;
            this.Close();
        }

        private void btnShowDialog_Click(object sender, EventArgs e)
        {
            if(folderBrowserDialog1.ShowDialog()==DialogResult.OK)
            {
                tbxFolderPath.Text = folderBrowserDialog1.SelectedPath;
            }
        }

        private void tbxPrdNo_Leave(object sender, EventArgs e)
        {
            if(!ERPConnection.CERPFunction.checkPrdNo(tbxPrdNo.Text.ToUpper().Trim()))
            {
                MessageBox.Show("输入的货品在ERP中不存在，请核查！");
            }
        }
    }
}
